//chainmine.txt - Part of a chain of mines. It just sits there and can be disarmed.
//  It goes off when a trigmine object sends it message 105. 
//Cell 0 - Difficulty of trap ... the total tool use needed to disarm.
//Cell 1 - The effect created.
//  0 - fiery boom (1-6 dam/level)
//  1 - magical boom (1-8 dam/level)
//  2 - spray acid (1-2 pts/level)
//  3 - spray poison (1-2 pts/level)
//  4 - spawn creature (damage is spawn #, not in game #)
//  5 - debuff shield/bless
//  6 - debuff slow
//Cell 2 - The damage of the trap. Should be roughly equal to the level of 
//  the character you want to kill with it. Defaults to 6.
//  If the mine spawns a creature, this is the town roster of the creature (not in game #).

beginobjectscript; 

variables;
short disarmed = 0;
short exploded = 0;
short near_char;
short r1;
short cur_tick;
short trap_level = 6;

body;

beginstate INIT_STATE;
	if (get_memory_cell(2) > 0)	
		trap_level = get_memory_cell(2);
	if (get_memory_cell(1) == 4)	
		trap_level = get_memory_cell(2);
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
	if ((disarmed) || (exploded))
		end();

	if (my_current_message() == 105) { // trigger trap
		exploded = 1;
		if (get_memory_cell(1) == 0) { // fire boom
			r1 = get_ran(trap_level,1,10);
			if (trap_level >= 100)
				r1 = r1 + 2000;
				else if (trap_level >= 40)
					r1 = r1 + 400;
			run_sparkles_on_object(ME,173,1,4);
	  		create_missile_spiral(154,20,8,2);
			damage_nearby(r1,8,2,0);
			}
		if (get_memory_cell(1) == 1) { // magic boom
			r1 = get_ran(trap_level,1,10);
			if (trap_level >= 100)
				r1 = r1 + 2000;
				else if (trap_level >= 40)
					r1 = r1 + 400;
			run_sparkles_on_object(ME,162,1,4);
	  		create_missile_spiral(155,20,8,2);
			damage_nearby(r1,8,1,0);
			}
		if (get_memory_cell(1) == 2) { // acid boom
			r1 = get_ran(trap_level,1,2);
			run_sparkles_on_object(ME,12,9,1);
			spray_missiles(52,8,8);
			status_nearby(r1,8,6,0);
			play_sound(165); 
			}
		if (get_memory_cell(1) == 3) { // poison boom
			r1 = get_ran(trap_level,1,2);
			run_sparkles_on_object(ME,13,9,1);
			spray_missiles(52,8,8);
			status_nearby(r1,8,2,0);
			play_sound(165); 
			}
		if (get_memory_cell(1) == 4) { // spawn creature
			spawn_creature(trap_level);
			run_sparkles_on_object(ME,177,1,4);
			if (get_level(8 + trap_level) > 5) {
				set_boss_level(8 + trap_level,1);
				set_char_status(8 + trap_level,0,8);
				set_char_status(8 + trap_level,8,8);
				}
			place_particle_num(trap_level + 8,10,7,10);
			}
		if (get_memory_cell(1) == 5) { // curse/weaken
			r1 = get_ran(trap_level,1,2);
			run_sparkles_on_object(ME,4,9,1);
			spray_missiles(37,8,8);
			status_nearby(-1 * r1,8,0,0);
			status_nearby(-1 * r1,8,8,0);
			play_sound(174); 
			}
		if (get_memory_cell(1) == 6) { // slow
			r1 = get_ran(trap_level,1,2);
			run_sparkles_on_object(ME,5,9,1);
			spray_missiles(42,8,8);
			status_nearby(-1 * r1,8,1,0);
			play_sound(240); 
			}
		
		kill_object(ME,0);
		end();
		}
break;

beginstate USE_STATE;
	if (exploded) {
		print_str("Disarm Mine: It's already gone off.");
		}
	else if (disarmed) {
		print_str("Disarm Mine: You already did.");
		}
	else if (get_memory_cell(0) >= 30) {
		print_str("Disarm Mine: You can't figure out how. It's too complicated.");
		}
	else if (get_stat(21) >= get_memory_cell(0)) {
		print_str("Disarm Mine: You manage to disable the trap!");
		pc_heard_sound(195);
		create_text_bubble("Click.");
		disarmed = 1;
		kill_object(ME,0);
		award_party_xp(BASE_TRAP_XP,trap_lev_to_xp_lev(get_memory_cell(0)));
		run_sparkles_on_object(ME,1,1,0);
		}
		else {
			create_text_bubble("Ssssss!");
			print_big_str("Disarm Mine: Your Mechanics skill isn't high enough. (Difficulty: ",get_memory_cell(0),").");
			}
break;